package org.brudywr.mychat.dao;

import java.util.Collection;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
/**
 * @author stas
 * @since 9/4/13
 */

@Repository
public class MessageRepositoryImpl implements MessageRepository {

    @Autowired
    private org.hibernate.SessionFactory sessionFactory;

    @Override
    public void addMessage(MessageEntity message) {
        sessionFactory.getCurrentSession().save(message);
    }

    @Override
    public Collection<MessageEntity> getMessages() {
        return sessionFactory.getCurrentSession().createQuery("from Messages")
                .list();
    }

    @Override
    public Collection<MessageEntity> getMessages(String nick) {
        return sessionFactory.getCurrentSession().createQuery("from Messages where nick='" + nick + "'")
                .list();
    }

    @Override
    public Collection<MessageEntity> getMessages(Date fromDate, Date toDate) {
        return null;
    }
}
